package main

import (
    "./balance"
    "time"
    "fmt"
    "strconv"
    "os"
    "math/rand"
)

func main() {
    // 模拟实例列表
    var insts []*balance.Instance
    for i := 0; i < 10; i++ {
        host := fmt.Sprintf("192.168.%d.%d", rand.Intn(255),i)
        port, _ := strconv.Atoi(fmt.Sprintf("880%d", i))
        one := balance.NewInstance(host, port)
        insts = append(insts, one)
    }

    // 默认用轮询, 如果有执行参数则用参数的
    var bname = "round"
    if len(os.Args) > 1 {
        bname = os.Args[1]
    }

    // 循环作业
    for {
        inst, err := balance.DoBalance(bname, insts)
        if err != nil {
            fmt.Println("do balance err")
            continue
        }
        fmt.Println(inst)
        time.Sleep(time.Second)
    }

}